package com.kingdee.openimport.patch_service.dao;

import com.kingdee.openimport.patch_service.model.PatchVersion;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

/**
 * Created by Niki on 2018/4/21 10:25
 */

public interface PatchVersionRepository extends JpaRepository<PatchVersion, Integer> {
    /**
     * 查询最新的版本
     * @return
     */
    @Query(value = "select version from t_bd_patch_version as a inner join (select max(date) as max_date from t_bd_patch_version ) as b on a.date = b.max_date ", nativeQuery = true)
    PatchVersion getLatestVersion();

    /**
     * 分页查询所有的版本。从新到旧
     * @param pageable
     * @return
     */
    @Query(value = "select version from PatchVersion order by id desc ")
    Page<String> getVersions(Pageable pageable);

    PatchVersion findByVersion(String version);
}
